package Service;

import domain.Transaction;
import utils.Tools;

import java.io.IOException;
import java.text.ParseException;
import java.util.List;

public class TransactionService {
    static Tools tools = new Tools();

    public static void viewCardTransactions(String cardId) throws IOException, ParseException {
        System.out.println("\n===== 该账号所有消费记录 =====");
        List<Transaction> transactions = tools.getTransaction(cardId);

        for (Transaction t : transactions) {
            System.out.println("卡号: " + t.getCardId() + " | 类型: " + t.getType() +
                    " | 金额: " + t.getAmount() + " | 时间: " + t.getTimestamp());
        }
    }
    public static void saveCardBalance(String userid, String type, double amount) throws IOException, ParseException {
        String cardId = tools.getCardByUserId(userid).getCardId();
        Transaction transaction = new Transaction();
        int id = tools.getID("transactionId");
        String transactionId = "T" + id;
        id++;
        tools.setID("transactionId", id);
        transaction.setTransactionId(transactionId);
        transaction.setCardId(cardId);
        transaction.setAmount(amount);
        transaction.setType(type);
        tools.setTransaction(transaction);
    }
}